var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    modalbtns: true,
    current: 0,
    xinxi: [{
        src: "../images/list1.png",
        tit: "病人信息"
      },
      {
        src: "../images/list2.png",
        tit: "诊疗信息"
      },
      {
        src: "../images/list3.png",
        tit: "联系人信息"
      },
      {
        src: "../images/list1.png",
        tit: "病人信息"
      },
      {
        src: "../images/list2.png",
        tit: "诊疗信息"
      },
      {
        src: "../images/list3.png",
        tit: "联系人信息"
      },
    ],
  },
  lookimgs(e) {
    console.log(e);
    var str = e.target.dataset.src;
    var arr = e.target.dataset.arr;
    wx.previewImage({
      current: str,
      urls: arr,
    })
  },
  //取消button
  closemodalbtns(e) {
    this.setData({
      modalbtns: true
    })
  },
  typesclick(e) {
    console.log(e)
    var that = this
    var self = this;
    var erjid = e.currentTarget.dataset.id;
    var ifkq = e.currentTarget.dataset.ifkq;
    var dex = e.currentTarget.dataset.dex;
    var openid = that.data.openid
    if (ifkq == 1) {
      //查询三级ID
      app.util.request({
        'url': 'entry/wxapp/Jdlistsanji',
        data: {
          parentid: erjid,
          openid: openid
        },
        success: function(res) {
          console.log(res)
          that.setData({
            dlist: res.data.data,
          })
        }
      })
    } else {
      app.util.request({
        'url': 'entry/wxapp/Jdlist',
        data: {
          fuleiid: erjid,
          openid: openid
        },
        success: function(res) {
          console.log(res)
          that.setData({
            dlist: res.data.data,
          })
        }
      })
    }

    if (dex == self.data.current) {
      return true;
    } else {
      self.setData({
        current: e.currentTarget.dataset.dex
      })
    }
    that.setData({
      erjid: erjid,
      ifkq: ifkq
    })
  },
  alldiy: function(e) {
    var that = this
    console.log(e)
    var erjid = e.currentTarget.dataset.id
    var ifkq = e.currentTarget.dataset.ifkq
    var ejdiv = e.currentTarget.dataset.erjid
    app.util.request({
      'url': 'entry/wxapp/Alljcxm',
      data: {
        p_id: erjid
      },
      success: function(res) {
        console.log(res)
        if (res.data !== 0) {
          if (ifkq == 1) {
            app.util.request({
              'url': 'entry/wxapp/Sanji',
              data: {
                id: erjid
              },
              success: function(res) {
                //console.log(res)
                that.setData({
                  sanji: res.data.data,
                  modalbtns: false,
                })
              }
            })
          } else {
            wx.navigateTo({
              url: '/hyb_yl/twosubpages/pages/jddiy/jddiy?erjid=' + erjid + '&ejdiv=' + ejdiv + '&xm=' + true,
            })
          }
        } else {
          if (ifkq == 1) {
            app.util.request({
              'url': 'entry/wxapp/Sanji',
              data: {
                id: erjid
              },
              success: function(res) {
                //console.log(res)
                that.setData({
                  sanji: res.data.data,
                  modalbtns: false,
                })
              }
            })
          } else {
            wx.navigateTo({
              url: '/hyb_yl/twosubpages/pages/jddiy/jddiy?erjid=' + erjid + '&ejdiv=' + ejdiv + '&xm=' + false,
            })
          }
        }
      }
    })
  },


  deleteimgs(e) {
    let that = this;
    let dex = e.currentTarget.dataset.dex;
    let jd_id = e.currentTarget.dataset.jd_id;
    let arrs = that.data.dlist;
    wx.showModal({
      content: '删除后不可恢复',
      success: function(res) {
        if (res.confirm) {
          app.util.request({
            'url': 'entry/wxapp/Delinfo',
            data: {
              jd_id: jd_id
            },
            success: function(res) {
              console.log(res)
              arrs.splice(dex, 1);
              that.setData({
                dlist: arrs
              })
            }
          })

        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
        var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var id = options.id
    var name = options.name
    var icon = options.icon
    var ksdesc = options.ksdesc
    if (options.huzopenid !== 'undefined') {
      that.setData({
        openid: options.huzopenid,
        disnone: options.huzopenid
      })
    } else {
      that.setData({
        openid: wx.getStorageSync('openid')
      })
    }
    that.setData({
      id: id,
      name: name,
      icon: icon,
      ksdesc: ksdesc,
    })
    app.util.request({
      'url': 'entry/wxapp/Scurl',
      success: function(res) {
        // console.log(res.data)
        that.setData({
          scurl: res.data.data
        })
      },
    })
    var show_title = options.name
    wx.setNavigationBarTitle({
      title: show_title
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    this.getAllerjifenl()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  //查询二级
  getAllerjifenl: function() {
    var that = this
    var id = that.data.id
    var openid = that.data.openid
    console.log(id)
    app.util.request({
      'url': 'entry/wxapp/Allerjifenl',
      data: {
        id: id,
        openid: openid
      },
      success: function(res) {
        console.log(res)
        var allerj = res.data.data
        var fuleiid = allerj[0].id
        var useropenid = openid
        var ifkq = allerj[0].ifkq
        if (ifkq ==1){
          app.util.request({
            'url': 'entry/wxapp/Jdlistsanji',
            data: {
              parentid: fuleiid,
              openid: useropenid
            },
            success: function (res) {
              console.log(res)
              that.setData({
                dlist: res.data.data,
              })
            }
          })
        }else{
          app.util.request({
            'url': 'entry/wxapp/Jdlist',
            data: {
              fuleiid: fuleiid,
              openid: useropenid
            },
            success: function (res) {
              //console.log(res)
              that.setData({
                dlist: res.data.data,
              })
            }
          })
        }

        that.setData({
          allerj: allerj
        })
      }
    })
  },
  speck: function(e) {
    //console.log(e)
    var jd_id = e.currentTarget.dataset.jd_id
    wx.navigateTo({
      url: '/hyb_yl/twosubpages/pages/jddiy/jddiy?jd_id=' + jd_id,
    })
  }
})